//5 Febrer 2011
package com.aiddea.maps;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


@SuppressWarnings("rawtypes")
public class HelloItemizedOverlay extends ItemizedOverlay {

	private ArrayList<GWI_Element> mGWI_Element = new ArrayList<GWI_Element>();

	private Context mContext;
	
	public HelloItemizedOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
		}

	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  setmContext(context);
	}
	
	// Mètode per anar afegint elements
	public void addGWI_Element(GWI_Element overlay) {
	    mGWI_Element.add(overlay);
	    populate(); 
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		return mGWI_Element.get(i).getOvItem();
	}
	
	@Override
	public int size() {
		return mGWI_Element.size();
	}
	
	@Override
	protected boolean onTap(int index) 	
	{
		
		GWI_Element item2 = GWI_info(index);  
		// Torradeta Test
		Toast.makeText(	getmContext(), 
						item2.getTitle() + " / " + item2.getSummary(), 
						Toast.LENGTH_LONG).show();

		return true;
	}
	
	
	public GWI_Element GWI_info(int index)
	{
		return (GWI_Element) mGWI_Element.get(index);
	}
	
	private void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	private Context getmContext() {
		return mContext;
	}
}
